package com.yyl.fmall.product.controller;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.yyl.fmall.product.entity.ProductParams;
import com.yyl.fmall.product.service.IProductCommentsService;
import com.yyl.fmall.product.service.IProductParamsService;
import com.yyl.fmall.product.service.IProductService;
import com.yyl.fmall.product.vo.ProductCommentsCountVo;
import com.yyl.fmall.product.vo.ProductDetailCommentsVo;
import com.yyl.fmall.product.vo.ProductDetailInfoVo;
import com.yyl.fmall.utils.CommonConstants;
import com.yyl.fmall.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商品 商品信息相关表：分类表，商品图片表，商品规格表，商品参数表 前端控制器
 * </p>
 *
 * @author YuanSir
 * @since 2022-11-07
 */
@RestController
@RequestMapping("/product")
@CrossOrigin
public class ProductController {
    
    @Autowired
    private IProductService productService;
    
    @Autowired
    private IProductParamsService productParamsService;
    
    @Autowired
    private IProductCommentsService productCommentsService;
    
    /**
     * 查询商品的基本信息
     * @param productId
     * @return
     */
    @GetMapping("/detail-info/{productId}")
    public R detailInfo(@PathVariable("productId") String productId){
    
        ProductDetailInfoVo productDetailInfoVo = productService.getDetailInfoById(productId);
        
        return R.ok().put(CommonConstants.R_MAP_KEY, productDetailInfoVo);
    
    }
    
    /**
     * 查询商品参数信息
     * @param productId
     * @return
     */
    @GetMapping("/detail-params/{productId}")
    public R detailParams(@PathVariable("productId") String productId){
    
        ProductParams productParams = productParamsService.getDetailParams(productId);
        
        return R.ok().put(CommonConstants.R_MAP_KEY, productParams);
        
    }
    
    
    @GetMapping("/detail-commontscount/{productId}")
    public R detailCommentCount(@PathVariable("productId") String productId){
    
        ProductCommentsCountVo productCommentsCountVo = productCommentsService.getDetailCommentCount(productId);
        
        return R.ok().put(CommonConstants.R_MAP_KEY, productCommentsCountVo);
        
    }
    
    
    @GetMapping("/detail-commonts/{productId}")
    public R detailCommonts(@PathVariable("productId") String productId, Long pageNum, Long limit){
    
        ProductDetailCommentsVo productDetailCommentsVo = productCommentsService.getDetailComments(productId, pageNum, limit);
        
        return R.ok().put(CommonConstants.R_MAP_KEY, productDetailCommentsVo);
    
        
    }
}
